import 'dart:convert';

import 'package:bot_toast/bot_toast.dart';
import 'package:common_utils/common_utils.dart';
import 'package:exams_app/gen_a/A.dart';
import 'package:exams_app/net/Address.dart';
import 'package:exams_app/net/DioManager.dart';
import 'package:exams_app/net/persisten_storage.dart';
import 'package:exams_app/widget/hexcolor.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class MyExamsDetailPage extends StatefulWidget {

  var examsid;

  MyExamsDetailPage(this.examsid);

  @override
  _MyExamsDetailPageState createState() => _MyExamsDetailPageState();
}

class _MyExamsDetailPageState extends State<MyExamsDetailPage> {


  var apidoneJson;

  /// 交卷 接口
  void requestDataWithComplete(var exam_id) async {
    String result =
    await DioUtils(url: await PersistentStorage().getStorage('urlStr'))
        .postModel(Address.getattt,
        model: 'res.exam', function_name: '_api_one',params: {'exam_id':exam_id});

    Map json = jsonDecode(result);

    apidoneJson = json;

    if(apidoneJson['data'][0]['type']==false){
      BotToast.showText(text: '考试尚未结束');
      Get.back();
    }

    LogUtil.e('////////////////// ${json}');

    setState(() {

    });


  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    requestDataWithComplete(widget.examsid);

  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[200],
      appBar: AppBar(
        centerTitle: true,
        leading: IconButton(
          onPressed: (){
            Get.back();
          },
          icon: Icon(Icons.arrow_back_rounded,color: Colors.white,),
        ),
        title: Text('考试详情'),
      ),
      body: Container(
        clipBehavior: Clip.antiAlias,
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(8.0),
        ),
        margin: EdgeInsets.only(left: 15, right: 15, top: 15),
        height: 330,
        child: Column(
          children: [
            Container(
              height: 100,
              color: Theme.of(context).primaryColor,
              child: Stack(
                children: [
                  Container(
                    margin: EdgeInsets.only(left: 10, top: 20),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          '此次考试分数',
                          style: TextStyle(
                              fontSize: 14, color: HexColor('#D7E6FF')),
                        ),
                        Text(
                          '${apidoneJson['data'][0]['scores'].toString()}分',
                          style: TextStyle(
                              color: Colors.white,
                              fontSize: 21,
                              fontWeight: FontWeight.w500),
                        ),
                      ],
                    ),
                  ),
                  Align(
                    alignment: Alignment.topRight,
                    child: Image.asset(A.assets_bookbg),
                  ),
                ],
              ),
            ),

            Container(
                margin: EdgeInsets.only(top: 30,left: 15,right: 0,bottom: 15),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('状态:${apidoneJson['data'][0]['state']}',style: TextStyle(fontSize: 16,color: HexColor('#666666')),),
                    Container(

                        width: 130,
                        child: Text('是否合格:${apidoneJson['data'][0]['type']}',style: TextStyle(fontSize: 16,color: HexColor('#666666')))),
                  ],
                )
            ),
            Container(
                margin: EdgeInsets.only(left: 15,right: 0),
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('错题数:${apidoneJson['data'][0]['error']}',style: TextStyle(fontSize: 16,color: HexColor('#666666')),),
                    Container(

                      child:Text('答对数:${apidoneJson['data'][0]['right']}',style: TextStyle(fontSize: 16,color: HexColor('#666666')),),
                      // color: Colors.red,
                      width: 130,
                    )
                  ],
                )
            ),
            Expanded(child:  Container(
              margin: EdgeInsets.only(left: 5, right: 5, top: 15),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceAround,
                children: [
                  RaisedButton(
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(5),
                      side: BorderSide(
                        width: 1,
                        color: HexColor('#D9D9D9'),
                        style: BorderStyle.solid,
                        // style: BorderStyle.none,
                      ),
                    ),
                    child: Text('返回'),
                    elevation: 0,
                    color: Colors.white,
                    onPressed: () {

                      Get.back();
                    },
                  ),
                ],
              ),
            )),
          ],
        ),
      ),
    );
  }

}
